<template>
	<view class="shopDetails">
		<tui-navigation-bar :titleSize="18" :titleLineHeight="18" :titlefontWeight="800" :isOpacity="false"
			@init="initNavigation" title="教练详情" backgroundColor="#fff" color="#000">
			<view class="tui-header-icon" :style="{ marginTop: top + 'px' }">
				<tui-icon name="arrowleft" color="#333" @click="back"></tui-icon>
			</view>
		</tui-navigation-bar>
		<view class="shopDetails_content" :style="{ marginTop: marginTp + 'px' }">
			<tutor-videoImg-swiper :ossUrl="ossUrl" :imgUrls="imgUrls"></tutor-videoImg-swiper>
			<view class="titleText">
				<view class="titleL">
					<view class="titleL_text"><text>{{tutorDetails.assistantName}}</text></view>
				</view>
				<view class="titleR">
					<text>{{tutorDetails.rates}}</text>
					<text class="priceTime">元/小时</text>
				</view>
			</view>
			<view class="tags">
				<view class="tag"><text>{{tutorDetails.personalSignature}}</text></view>
			</view>
			<view class="timeText">
				<text>营业时间：{{tutorDetails.begintime}}—{{tutorDetails.endtime}}</text>
			</view>
			<view class="addressText">
				教练地址：<text class="ct">{{tutorDetails.poi&&tutorDetails.poi.district}}</text>
			</view>
			<view class="tabList">
				<view class="tabList_tab">
					<tutor-tab :list="['最新动态','评价列表']" @clickSwtichTab="clickSwtichTab"
						:atciveIndex="atciveIndex"></tutor-tab>
				</view>
				<view class="contentDynamic">
					<z-paging ref="paging" :fixed="false" v-model="listData" @query="queryList">
						<view class="shopImg" v-if="!atciveIndex">
							<!-- <text class="newest">最新动态</text>
							<view style="margin-top: 24rpx;margin-bottom: 40rpx;">
								 <tutor-dynamicItem :dynamicList="upDymicList" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
							<text class="newest" >动态列表</text> -->
							<view>
								<tutor-dynamicItem :dynamicList="listData" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
						</view>
						<view class="appraiseItems" v-else>
							<tutor-appraiseItem :ossUrl="ossUrl" :listData="listData"></tutor-appraiseItem>
						</view>
					</z-paging>
				</view>
			</view>
		</view>
		<!-- 教练邀约 -->
		<view class="footer">
			<tui-form-button @click="openvisible" radius="70rpx" size="34" color="#fff" width="690rpx" height="84rpx"
				background="#2FD7D3">
				<tui-icon name="alarm" color="#fff" :size="28" margin="0 8rpx 0 0"></tui-icon>
				邀约
			</tui-form-button>
		</view>
		<!-- 邀约弹窗 -->
		<tutor-invite :hours="hours" :assistantId="id" :merchantId="tutorDetails.merchantId"
			@confimInvite="confimInvite" @clear="clearInvite" :visible="inviteVisible"
			:categoryId="tutorDetails.categoryId"></tutor-invite>

		<!-- <tui-drawer mode="bottom" :visible="visible" @close="closeDrawer">
					<solt>
						<view class="invite-container">
							<view class="title">
								<text class="titleTxt">教练邀约</text>
								<view class="close" @tap="visible=false">
									<image class="closeImg" src="../../../../static/user/icon_off@2x.png"></image>
								</view>
							</view>
							<view class="invite-content">
								<InviteItem ref="inviteItemRef" :categoryId="tutorDetails.categoryId"></InviteItem>
							</view>
							<view class="inite-agreement">
								<view class="contents"> 
									<view @tap="isAgreement=!isAgreement" :class="isAgreement ? 'checked':'isChecked'"></view>
									<view class="agreement_content">
										<text>已阅读并同意</text>
										<text class="place" @tap="orderInstructions(3)">《下单须知》</text>
										<text>与</text>
										<text class="rule"  @tap="orderInstructions(4)">《计费规则》</text>
									</view>
								</view>
							</view>
							<tui-form-button @click="inviteVerify" radius="20rpx" size="32" color="#fff" width="690rpx"
								height="84rpx" background="#2FD7D3">
								<tui-icon name="alarm" color="#fff" :size="28" margin="0 8rpx 0 0"></tui-icon>
								确认邀约
							</tui-form-button>
						</view>
					</solt>
				</tui-drawer> -->
	</view>
</template>

<script>
	import {
		getTutorDetails,
		getTutorTime
	} from "@/http/api/tutor/tutor.js"
	import {
		getAppraiseList
	} from "@/http/api/appraise/appraise.js"
	import {
		myDynamicList
	} from "@/http/api/dynamic/dynamic.js"
	import {
		invitePlace
	} from "@/http/api/order/order.js"
	import InviteItem from './compontents/inviteItem.vue';
	export default {
		data() {
			return {
				top: 0, //标题图标距离顶部距离
				marginTp: 0,
				isAgreement: false,
				hours: [],
				id: '', //教练id
				inviteVisible: false, //邀约填写项
				listData: [], //评价数据
				upDymicList: [], //最新动态
				dymicList: [], //动态列表
				ossUrl: getApp().globalData.ossurl, //图片前缀
				tutorDetails: {}, //教练信息
				imgList: ['https://img1.baidu.com/it/u=802052110,461511387&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=214',
					'https://img1.baidu.com/it/u=802052110,461511387&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=214'
				],
				atciveIndex: 0, //切换商家图片和教练列表
			}
		},
		onLoad(options) {
			if (options) {
				this.id = options.id
				this.getDetails()
				uni.$on('refresh', (e) => {
					if (e) {
						this.getDetails()
					}
				})
				//  getTutorTime(options.id).then(res=>{
				// 	 console.log('教练可预约时间',res)
				//  })
			}
		},
		components: {
			InviteItem
		},
		computed: {
			imgUrls() {
				return this.tutorDetails.detailImgs
			},
			// videoline(){
			// 	if(this.tutorDetails.detailImgs&&this.tutorDetails.detailImgs.length || false){  
			// 		if(this.isImage(this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1])){
			// 			 return ''
			// 		}else{
			// 			 return  this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1]
			// 		} 
			// 	}
			// }
		},
		methods: {
			orderInstructions(type) {
				uni.navigateTo({
					url: '/pages/mine/modules/richText/richText?type=' + type
				})
			},
			isImage(filename) {
				const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'];
				const fileExtension = filename.slice(filename.lastIndexOf('.'));
				return imageExtensions.includes(fileExtension.toLowerCase());
			},
			initNavigation(e) {
				this.top = e.top;
				this.marginTp = e.height
			},
			back() {
				uni.navigateBack();
			},
			examine(arr, index) {
				uni.previewImage({
					urls: arr,
					current: index
				});
			},
			clickSwtichTab(data) {
				this.atciveIndex = data.index
				this.$refs.paging.reload()
			},
			openvisible() {
				this.inviteVisible = true
			},
			//成功邀约
			confimInvite() {
				this.inviteVisible = false
				this.getDetails()
			},
			//关闭邀约
			clearInvite() {
				this.inviteVisible = false
			},
			//获取教练详情
			getDetails() {
				getTutorDetails({
					id: this.id
				}).then(res => {
					if (res.code === 200) {
						this.tutorDetails = res.data
						const hous = res.data.category.hours || 1
						this.hours = this.generateHourOptions(hous);
					}
					console.log(res, '获取当前教练信息')
				})
			},
			generateHourOptions(minHours) {
				const maxHours = 8; // 假设最大为6小时
				const result = [];

				for (let i = minHours; i <= maxHours; i++) {
					result.push({
						name: `${i}小时`,
						id: i
					});
				}

				return result;
			},
			//加载动态和评价列表
			queryList(pageNo, pageSize) {
				if (!this.atciveIndex) {
					//获取最新动态
					// myDynamicList({pageNum:pageNo,pageSize,queryType:2}).then(res => {
					// 	if (res.code == 200) {
					// 		  this.upDymicList=res.rows&&res.rows.slice(0,1) || [] 
					// 	} else {
					// 		this.$utils.toast(res.msg);
					// 	}
					// }) 
					myDynamicList({
						pageNum: pageNo,
						pageSize,
						fromType: 2,
						userId: this.tutorDetails.id
					}).then(res => {
						if (res.code == 200) {
							this.$refs.paging.complete(res.rows);
						} else {
							this.$utils.toast(res.msg);
						}
					})
				} else {
					//获取教练评论
					getAppraiseList({
						pageNum: pageNo,
						pageSize,
						commentType: 2,
						beUserType: 2,
						beUserId: this.tutorDetails.id
					}).then(res => {
						if (res.code == 200) {
							this.$refs.paging.complete(res.rows);
						} else {
							this.$utils.toast(res.msg);
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './tutorDetails.scss';
</style>